%%%-------------------------------------------------------------------
%%% @author Rain
%%% @doc
%%% @end
%%%-------------------------------------------------------------------
-module(nif_test).
-author("Rain").

%% API
-export([init/0, nif_hello_world/0]).

-define(NOT_LOADED, not_loaded(?LINE)).
-on_load(init/0).

init() ->
    PrivDir = case code:priv_dir(?MODULE) of
                  {error, _} ->
                      EbinDir = filename:dirname(code:which(?MODULE)),
                      AppPath = filename:dirname(EbinDir),
                      filename:join(AppPath, "priv");
                  Path ->
                      Path
              end,
    erlang:load_nif(filename:join(PrivDir, "hello_world"), 0).

not_loaded(Line) ->
    erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).

nif_hello_world() ->
    ?NOT_LOADED.